package replicant1;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;



public class GameServerMain {

	public static void main(String[] args) throws InvalidName, ServantAlreadyActive, WrongPolicy, ObjectNotActive, FileNotFoundException, AdapterInactive {
		ORB orb = ORB.init(args, null);
		POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
		
		GameServerImpl ASServer = new GameServerImpl("AS");
		ASServer.startUdpServer();
		byte[] ASid = rootPOA.activate_object(ASServer);
		org.omg.CORBA.Object ASref = rootPOA.id_to_reference(ASid);
		String ASior = orb.object_to_string(ASref);
		PrintWriter ASfile = new PrintWriter("ASior.txt");
		System.out.println(ASior);
		ASfile.println(ASior);
		ASfile.close(); 
		
		GameServerImpl EUServer = new GameServerImpl("EU");
		EUServer.startUdpServer();
		byte[] EUid = rootPOA.activate_object(EUServer);
		org.omg.CORBA.Object EUref = rootPOA.id_to_reference(EUid);
		String EUior = orb.object_to_string(EUref);
		PrintWriter EUfile = new PrintWriter("EUior.txt");
		System.out.println(EUior);
		EUfile.println(EUior);
		EUfile.close();
		
		
		GameServerImpl NAServer = new GameServerImpl("NA");
		NAServer.startUdpServer();
		byte[] NAid = rootPOA.activate_object(NAServer);
		org.omg.CORBA.Object NAref = rootPOA.id_to_reference(NAid);
		String NAior = orb.object_to_string(NAref);
		PrintWriter NAfile = new PrintWriter("NAior.txt");
		System.out.println(NAior);
		NAfile.println(NAior);
		NAfile.close();
		
		rootPOA.the_POAManager().activate();
		orb.run();

	}

}
